using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using BUS;
using Utility;

public partial class Admin_nhanviensua : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
          
            LoadData();
            LoadDDL();
        }
    }
    private void LoadData()
    {
        try
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            tbnhanvienDTO nv = tbnhanvienBUS.GetByID(id);
            if (nv != null)
            {

                //txt_MaSp.Text = sp.Masp.ToString();
                txt_tennv.Text = nv.Tennv;
                txt_ngaysinh.Text = nv.Ngaysinh.ToString();
                txt_gioitinh.Text = nv.Gioitinh.ToString();
                txt_taikhoan.Text = nv.Taikhoan;
                txt_matkhau.Text = nv.Matkhau;
                ddl_cv.SelectedValue =nv.Machucvu.ToString();
                hd_mnv.Value = nv.Manv.ToString();
               

            }
        }
        catch
        {
            Response.Redirect("nhanvienlist.aspx");
        }
    }
    protected void btn_Update_Click(object sender, EventArgs e)
    {
        try
        {
            tbnhanvienDTO nhanvien = new tbnhanvienDTO();
            //sanpham.Masp = int.Parse(txt_MaSp.Text);
            nhanvien.Manv =int.Parse( hd_mnv.Value.ToString());
            nhanvien.Tennv =txt_tennv.Text;
            nhanvien.Ngaysinh = DateTime.Parse(txt_ngaysinh.Text);
            nhanvien.Gioitinh = int.Parse(txt_gioitinh.Text);
            nhanvien.Taikhoan = txt_taikhoan.Text;
            nhanvien.Matkhau = txt_ngaysinh.Text;
            nhanvien.Machucvu = int.Parse(ddl_cv.SelectedValue.ToString());

            tbnhanvienBUS.Update(nhanvien);
            Response.Redirect("nhanvienlist.aspx");
            Label_thanhcong.Text = tbnhanvienBUS.error;
        }

        catch
        {
            Label_thanhcong.Text = tbnhanvienBUS.error;
            Response.Redirect("nhanvienlist.aspx");
        }
    }
    private void LoadDDL()
    {
        ddl_cv.DataSource = tbchucvuBUS.GETAll();
        ddl_cv.DataTextField = tbchucvuDTOColumn.Tenchucvu.ToString();
        ddl_cv.DataValueField = tbchucvuDTOColumn.Machucvu.ToString();
        ddl_cv.DataBind();
    }
}
